package com.woniuxy.main.chat_yj.dao;

import com.woniuxy.main.chat_yj.model.ChatRecord;
import com.woniuxy.main.chat_yj.model.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface UserDao {
	

	/**
	 * 查询当前登录者的信息   姓名（英文）、昵称（中文）、头像
	 * @param username
	 * @return
	 */
	@Select("SELECT user_headimg,user_name,user_nickname FROM user WHERE user_name = #{username} limit 0,1")
	@Results({
		@Result(column = "user_headimg",property = "img"),
		@Result(column = "user_name",property = "username"),
		@Result(column = "user_nickname",property = "name"),
		@Result(column = "user_nickname",property = "id")
	})
    User getUserByName(@Param("username") String username);
 
	
	/**
	 * 获取用户的好友列表
	 * @param uid
	 * @return 我主动添加粉丝
	 */
    @Select("select user_headimg,user_nickname from follow a inner join user b on b.user_id = a.user_id  where followed_id= #{uid}  and follow_state =1 and a.flag = 1")
	@Results({
		@Result(column = "user_headimg",property = "img"),
		@Result(column = "user_nickname",property = "name"),
		@Result(column = "user_nickname",property = "id")
	})
    List<User> getMyAdd(Integer uid);
   
    /**
	 * 获取用户的好友列表
	 * @param uid
	 * @return 我的关注者 添加了我
	 */
	@Results({
		@Result(column = "user_headimg",property = "img"),
		@Result(column = "user_nickname",property = "name"),
		@Result(column = "user_nickname",property = "id")
	})
    @Select("select user_headimg,user_nickname from follow m inner join user n on n.user_id = m.followed_id  where m.user_id= #{uid}  and m.follow_state =1 and m.flag = 1")
    List<User> getAddMe(Integer uid);
    
    
  
    /**
     * 获取与好友的聊天记录
     * @param cr
     * @return
     */
    @Select("select *from chat_record where (send_user=#{send_user}  and receive_user = #{receive_user}  )  or  (  send_user=#{receive_user} and receive_user =#{send_user}  ) order by create_date asc")
    List<ChatRecord> query( ChatRecord cr);
    
    
//    (select user_headimg,user_nickname from follow f inner 
//    		join user u on u.user_id = f.user_id 
//    		where followed_id=1001  and follow_state =1)
//    or (select user_headimg,user_nickname from follow f 
//    		inner join user u on u.user_id = f.followed_id  
//    		where user_id=1001  and follow_state =1)
    
    
}
